from pydantic import BaseModel, ConfigDict
from typing import Optional, List
from datetime import datetime


class FirmwareInfo(BaseModel):
    """单个固件信息"""
    version: Optional[str] = None
    version_code: Optional[int] = None
    file_name: Optional[str] = None
    file_path: Optional[str] = None
    file_size: Optional[int] = None
    changelog: Optional[str] = None


class OTAFirmwareBase(BaseModel):
    """OTA固件基础模型"""
    cm3_version: Optional[str] = None
    cm3_version_code: Optional[int] = None
    cm3_changelog: Optional[str] = None
    dsp_version: Optional[str] = None
    dsp_version_code: Optional[int] = None
    dsp_changelog: Optional[str] = None
    remark: Optional[str] = None


class OTAFirmwareCreate(OTAFirmwareBase):
    """创建OTA固件"""
    pass


class OTAFirmwareUpdate(BaseModel):
    """更新OTA固件"""
    cm3_version: Optional[str] = None
    cm3_version_code: Optional[int] = None
    cm3_changelog: Optional[str] = None
    dsp_version: Optional[str] = None
    dsp_version_code: Optional[int] = None
    dsp_changelog: Optional[str] = None
    is_active: Optional[bool] = None
    remark: Optional[str] = None


class OTAFirmwareResponse(OTAFirmwareBase):
    """OTA固件响应模型"""
    model_config = ConfigDict(from_attributes=True)
    
    id: int
    cm3_file_name: Optional[str] = None
    cm3_file_path: Optional[str] = None
    cm3_file_size: Optional[int] = None
    dsp_file_name: Optional[str] = None
    dsp_file_path: Optional[str] = None
    dsp_file_size: Optional[int] = None
    is_active: bool
    created_at: datetime
    updated_at: datetime


class OTAFirmwareUploadResponse(BaseModel):
    """OTA固件上传响应"""
    success: bool
    message: str
    firmware: Optional[OTAFirmwareResponse] = None


class OTAFirmwareListResponse(BaseModel):
    """OTA固件列表响应"""
    total: int
    items: List[OTAFirmwareResponse]


class OTAFirmwareVersionResponse(BaseModel):
    """OTA固件版本信息响应"""
    model_config = ConfigDict(from_attributes=True)
    
    cm3_info: Optional[FirmwareInfo] = None
    dsp_info: Optional[FirmwareInfo] = None
    is_active: bool
    created_at: datetime 